package com.huazi.user.registration.dao.imp;

import com.huazi.user.registration.dao.User_Disease_infoi;
import com.huazi.user.registration.entity.DiseaseInfo;
import com.huazi.user.registration.tool.BaseDao;

import javax.xml.transform.Result;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * 用户查看自己病例的方法
 */
public class User_Disease_infoImpl extends BaseDao implements User_Disease_infoi {
    ResultSet rs = null;

    /**
     * 查看病例的方法
     *
     * @param userId
     * @return
     */
    @Override
    public List<DiseaseInfo> selectInfo(Integer userId) {
        List<DiseaseInfo> list = new ArrayList<>();
        DiseaseInfo info = null;
        //查询用户病例的方法
        String sql = "select dd.id,fc.`name`,dd.usertype,di.doctorname,dd.diagnosedate FROM doctor_diagnose dd,frontdesk_card fc,doctor_information di WHERE dd.userid=fc.id AND dd.doctorid=di.doctorId AND fc.id=? ORDER BY dd.diagnosedate DESC;";
        rs = excuteQuery(sql, userId);
        try {
            while (rs.next()) {
                Integer id = rs.getInt(1);
                String uname = rs.getString(2);
                String type = rs.getString(3);
                String dname = rs.getString(4);
                String time = rs.getTime(5).toString();
                info = new DiseaseInfo(id, uname, type, dname, time);
                list.add(info);

            }
        } catch (SQLException sqlException) {

        }
        return list;
    }
}
